<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>loopsegp</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="loopseg.html" title="loopseg" />
    <link rel="next" href="looptseg.html" title="looptseg" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">loopsegp</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="loopseg.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="looptseg.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="loopsegp"></a>
      <div class="titlepage"></div>
      <a id="Indexloopsegp" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">loopsegp</span>
        </h2>
        <p>loopsegp — 
      Control signals based on linear segments.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120162944"></a>
        <h2>Description</h2>
        <p>
    Generate control signal consisiting of linear segments delimited
    by two or more specified points. The entire envelope can be looped
    at time-variant rate. Each segment coordinate can also be varied
    at k-rate. 
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120238272"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ksig <span class="command"><strong>loopsegp</strong></span>  kphase, kvalue0, kdur0, kvalue1 \
      [, kdur1, ... , kdurN-1, kvalueN]</pre>
      </div>
      <div class="refsect1">
        <a id="idp120241024"></a>
        <h2>Performance</h2>
        <p>
      <span class="emphasis"><em>ksig</em></span> - output signal
    </p>
        <p>
      <span class="emphasis"><em>kphase</em></span> - point of the sequence read, expressed as a fraction of a cycle (0 to 1)
    </p>
        <p>
      <span class="emphasis"><em>kvalue0</em></span> ...<span class="emphasis"><em>kvalueN</em></span>  - values of points
    </p>
        <p>
      <span class="emphasis"><em>kdur0</em></span> ...<span class="emphasis"><em>kdurN-1</em></span>  -  duration of points expessed in fraction of a cycle
    </p>
        <p>
      <span class="emphasis"><em>loopsegp</em></span> opcode is similar to <a class="link" href="loopseg.html" title="loopseg"><em class="citetitle">loopseg</em></a>; the only difference is that, instead of frequency,  a time-variant phase is required. If you use <a class="link" href="phasor.html" title="phasor"><em class="citetitle">phasor</em></a> to get the phase value, you will have a behaviour identical to <a class="link" href="loopseg.html" title="loopseg"><em class="citetitle">loopseg</em></a>, but interesting results can be achieved when using phases having non-linear motions, making <span class="emphasis"><em>loopsegp</em></span> more  powerful and general than <a class="link" href="loopseg.html" title="loopseg"><em class="citetitle">loopseg</em></a>.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120251376"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the loopsegp opcode. It uses the file <a class="ulink" href="examples/loopsegp.csd" target="_top"><em class="citetitle">loopsegp.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp120253232"></a>
          <p class="title">
            <strong>Example 437. Example of the loopsegp opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac      <span class="comment">;;;realtime audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o loopsegp.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="oblock">instr</span> 1
ktrig <span class="opc">metro</span> 22<span class="op">/</span>8 <span class="comment">; triggers used to generate new direction values</span>
kdir  <span class="opc">trandom</span> ktrig,<span class="op">-</span>2.99,2.99
kdir  <span class="op">=</span>       0.5<span class="op">*</span><span class="opc">int</span>(kdir) <span class="comment">; kdir will either -1, -0.5, 0, 0.5 or 1</span>
<span class="comment">; kphase - looping pointer</span>
kphase <span class="opc">phasor</span> kdir
<span class="comment">; a loop sequence of midi note numbers and durations</span>
knote <span class="opc">loopsegp</span>  kphase, 40,1,40,0, 43,1,43,0, 49,2,48,0, \
 47,1,47,0, 46,1,46,0, 46,1,47,0, 49,1,49,0, 43,1,43,0, 46,1,46,0, 40,1,39,0    
kmul  <span class="opc">rspline</span> 0.1,0.8,0.5,5                         <span class="comment">; modulation of buzz tone</span>
asig  <span class="opc">gbuzz</span>   0.2, <span class="opc">cpsmidinn</span>(knote), 30, 3, kmul, 1 <span class="comment">; buzz tone</span>
      <span class="opc">outs</span>    asig, asig
      
      <span class="opc">schedkwhen</span> ktrig,0,0,2,0,0.1 <span class="comment">; play metronome</span>
<span class="oblock">endin</span>

<span class="oblock">instr</span> 2 <span class="comment">; metronome</span>
acps  <span class="opc">expon</span>   180<span class="op">+</span><span class="opc">rnd</span>(40),p3,50
aamp  <span class="opc">expon</span>   0.05<span class="op">+</span><span class="opc">rnd</span>(0.05),p3,0.001
asig  <span class="opc">poscil</span>  aamp<span class="op">-</span>0.001,acps,2
      <span class="opc">outs</span>    asig,asig
<span class="oblock">endin</span>

<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="comment">; cosine wave.</span>
<span class="stamnt">f</span> 1 0 16384 11 1
<span class="comment">; sine wave.</span>
<span class="stamnt">f</span> 2 0 16384 10 1

<span class="stamnt">i</span> 1 0 360 0.25

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp120255152"></a>
        <h2>Credits</h2>
        <p>Written by Gabriel Maldonado.</p>
        <p>New in Csound 5. (Previously available only on CsoundAV)</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="loopseg.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="looptseg.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">loopseg </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> looptseg</td>
        </tr>
      </table>
    </div>
  </body>
</html>
